package com.blog.system.mapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blog.system.domain.RoomTime;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 自习室时间段Mapper接口
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
public interface RoomTimeMapper extends BaseMapper<RoomTime>

{
    /**
     * 查询自习室时间段
     * 
     * @param id 自习室时间段主键
     * @return 自习室时间段
     */
    public RoomTime selectRoomTimeById(Long id);

    /**
     * 查询自习室时间段列表
     * 
     * @param roomTime 自习室时间段
     * @return 自习室时间段集合
     */
    public List<RoomTime> selectRoomTimeList(RoomTime roomTime);

    /**
     * 新增自习室时间段
     * 
     * @param roomTime 自习室时间段
     * @return 结果
     */
    public int insertRoomTime(RoomTime roomTime);

    /**
     * 修改自习室时间段
     * 
     * @param roomTime 自习室时间段
     * @return 结果
     */
    public int updateRoomTime(RoomTime roomTime);

    /**
     * 删除自习室时间段
     * 
     * @param id 自习室时间段主键
     * @return 结果
     */
    public int deleteRoomTimeById(Long id);

    /**
     * 批量删除自习室时间段
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteRoomTimeByIds(String[] ids);


    public  List <RoomTime >getRoomsByUserName(String userName);

    @Select("SELECT COUNT(*) FROM room_time " +
            "WHERE seat_id = #{seatId} " +
            "AND data = #{reserveDate}" +
            "AND room_id = #{roomId}" +
            "AND ((start_time < #{endTime} AND stop_time > #{startTime}))")
    int countTimeConflict(@Param("roomId") String roomId,@Param("seatId") String seatId,
                          @Param("reserveDate") LocalDate reserveDate,
                          @Param("startTime") LocalDateTime startTime,
                          @Param("endTime") LocalDateTime endTime);
    public String  getStudyLength (String userName);

    public String  getAvgDaily (String userName);



}
